import 'package:flutter/material.dart';

///搜索控件widget
class SearchBar extends StatelessWidget {
  TextEditingController _keywordController = new TextEditingController();

  @override
  Widget build(BuildContext context) {
    return DecoratedBox(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10),
      ),
      child: Padding(
        padding: const EdgeInsets.symmetric(
          horizontal: 4,
          vertical: 8,
        ),
        child: Row(
          children: [
            const Icon(
              Icons.search,
              color: Colors.grey,
            ),
            Expanded(
              child: TextField(
                decoration: InputDecoration(
                  // 输入框decoration属性
                  // contentPadding: const EdgeInsets.symmetric(vertical: 1.0,horizontal: 1.0),
                  contentPadding: new EdgeInsets.all(0),
                  border: InputBorder.none,
                  hintText: " 搜索",
                  hintStyle: new TextStyle(
                    fontSize: 14,
                  ),
                ),
                controller: _keywordController,
              ),
            ),
            GestureDetector(
              onTap: _keywordController.clear,
              child: const Icon(
                Icons.clear,
                color: Colors.grey,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
